package com.spring.framework.aop.annotation.param;

import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import java.util.Date;

/**
 * 启动类
 *
 * @author xuweizhi
 * @since 2020/12/16 15:08
 */
@Configuration
@EnableAspectJAutoProxy
@ComponentScan(basePackages = "com.spring.framework.aop.annotation.param")
public class AnnotationConfig {

	@Test
	public void aspectArgument() {
		//1 获取容器
		AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(AnnotationConfig.class);
		//2 获取目标类bean
		AspectArgumentTarget aspectArgumentTarget = ac.getBean("aspectArgumentTarget", AspectArgumentTarget.class);
		//2 调用目标方法
		Date target = aspectArgumentTarget.target();
		System.out.println(" returned value: " + target);
	}

	@Test
	public void aspectAttribute() {
		//1 获取容器
		AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(AnnotationConfig.class);
		//2 获取目标类bean
		AspectAttributeTarget aspectAttributeTarget = ac.getBean("aspectAttributeTarget", AspectAttributeTarget.class);
		//2 调用目标方法
		AspectAttributeTarget aspectAttributeTarget1 = new AspectAttributeTarget();
		System.out.println("AspectAttributeTarget: " + aspectAttributeTarget1);
		Date target = aspectAttributeTarget.target(33, "参数", aspectAttributeTarget1);
		System.out.println(" returned value: " + target);
	}



}
